#include "Test.h"
#include "InterOpIO.h"
#include "InterOpObject.h"
#include "InterOpDocumentInstance.h"
#include "topology/TopoBuilder.hpp"
#include "topology/TopoCompound.hpp"
#include "occtio/OCCTTool.hpp"
#include "../utils/logger.h"

void NestedExchangeShapeToFlatRecursion(std::vector<std::shared_ptr<AMCAX::Exchange::InterOpObject>>& flat_shapes,std::shared_ptr<AMCAX::Exchange::InterOpObject> raw_shape)
{
    if (raw_shape->childs.size() > 0)
    {
        for(auto& child_exchange_shape : raw_shape->childs)
        {
            flat_shapes.push_back(child_exchange_shape);
            NestedExchangeShapeToFlatRecursion(flat_shapes, child_exchange_shape);
        }
    }
}

void NestedExchangeShapeToFlat(std::vector<std::shared_ptr<AMCAX::Exchange::InterOpObject>>& flat_shapes,std::vector<std::shared_ptr<AMCAX::Exchange::InterOpObject>> raw_shape)
{
    for(auto& raw_shape_item : raw_shape)
    {
        flat_shapes.push_back(raw_shape_item);
        NestedExchangeShapeToFlatRecursion(flat_shapes, raw_shape_item);
    }
}

void Convert(std::string inputFilePath, std::string outputFilePath,bool isDebug)
{
    std::string license_25_1("");
    AMCAX::Exchange::InterOp::IO::GetInstance().CheckLicense(license_25_1);

#if 1    
    // Default options;
    AMCAX::Exchange::InterOp::FacetOptions facetOptions;
    AMCAX::Exchange::InterOp::IO::GetInstance().Convert(inputFilePath, outputFilePath);
    auto info = AMCAX::Exchange::InterOp::IO::GetInstance().GetMetaData(inputFilePath, outputFilePath, facetOptions);
#else
    std::vector<std::shared_ptr<AMCAX::Exchange::InterOpObject>> exchangeObjectList;
    std::shared_ptr<AMCAX::Exchange::InterOp::InterOpDocumentInstance> rootInterOpDocInstance;
    AMCAX::Exchange::InterOp::IO::GetInstance().ReadFromFilePath(inputFilePath, &exchangeObjectList, &rootInterOpDocInstance);
    AMCAX::Exchange::InterOp::IO::GetInstance().WriterToFile(outputFilePath, exchangeObjectList, rootInterOpDocInstance);

#endif
    DEBUG("Convert done") ;
}
